import {createRouter, createWebHistory} from 'vue-router'

const routes = [
    {
        path: '/',
        name: 'home',
        meta: {
            title: '首页'
        },
        component: () => import('@/view/home/Home.vue'),
        redirect: '/welcome',
        children: [
            {
                path: '/welcome',
                name: 'welcome',
                component: () => import('@/view/home/Welcome.vue'),
                meta: {
                    title: '欢迎页'
                }
            },
            {
                path: '/system',
                name: 'system',
                meta: {
                    title: '系统管理'
                },
                children: [
                    // {
                    //     path: 'sms',
                    //     name: 'sms',
                    //     component: () => import('@/view/sms/SmsView.vue'),
                    //     meta: {
                    //         title: '短信验证码'
                    //     }
                    // },
                    {
                        path: 'account',
                        name: 'account',
                        component: () => import('@/view/sys/account/AccountView.vue'),
                        meta: {
                            title: '后台用户管理'
                        }
                    },
                    {
                        path: 'role',
                        name: 'role',
                        component: () => import('@/view/sys/role/RoleView.vue'),
                        meta: {
                            title: '角色管理'
                        }
                    },
                    {
                        path: 'menu',
                        name: 'menu',
                        component: () => import('@/view/sys/menu/MenuList.vue'),
                        meta: {
                            title: '菜单管理'
                        }
                    }
                ]
            },
            // {
            //     path: '/status',
            //     name: 'status',
            //     meta: {
            //         title: '系统状态'
            //     },
            //     children: [
            //         {
            //             path: 'log',
            //             name: 'log',
            //             component: () => import('@/view/sys/log/AccessLog.vue'),
            //             meta: {
            //                 title: '系统日志'
            //             }
            //         },
            //         {
            //             path: 'param',
            //             name: 'param',
            //             component: () => import('@/view/sys/param/SystemParamView.vue'),
            //             meta: {
            //                 title: '系统参数'
            //             }
            //         },
            //         {
            //             path: 'dict',
            //             name: 'dict',
            //             component: () => import('@/view/sys/param/DictView.vue'),
            //             meta: {
            //                 title: '系统字典'
            //             }
            //         }
            //     ]
            // },
            {
                path: '/:pathMatch(.*)*',
                name: 'NotFound',
                component: () => import('@/view/NotFoundView.vue'),
                meta: {
                    title: '页面走丢了＞﹏＜'
                }
            }
        ]
    },
    {
        path: '/center',
        name: 'center',
        component: () => import('@/view/sys/account/PersonalCenter.vue'),
        meta: {
            title: '个人中心 ( •̀ ω •́ )✧'
        }
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/view/login/Longin.vue'),
        meta: {
            title: '欢迎回来 o((>ω< ))o'
        }
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} - 伏羲管理系统`;
    let token = window.localStorage.getItem("token")
    token || to.path === '/login' ? next() : next({path: '/login'});
});

export default router;
